#include "zrtc.h"


TwiMaster rtc(true);

// Read 'count' bytes from the DS1307 starting at 'address'
uint8_t readDS1307(uint8_t address, uint8_t *buf, uint8_t count) 
{
  // issue a start condition, send device address and write direction bit
  if (!rtc.start(DS1307ADDR | I2C_WRITE)) return false;

  // send the DS1307 address
  if (!rtc.write(address)) return false;

  // issue a repeated start condition, send device address and read direction bit
  if (!rtc.restart(DS1307ADDR | I2C_READ))return false;

  // read data from the DS1307
  for (uint8_t i = 0; i < count; i++) {

    // send Ack until last byte then send Ack
    buf[i] = rtc.read(i == (count-1));
  }

  // issue a stop condition
  rtc.stop();
  return true;
}

// --------------- ZRTC END -------------




